// pages_report/components/car-charging/car-charging.js
import dayjs from 'dayjs'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    m1:{
      type: Object,
      default:() => ({})
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    reportInfo:{}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    transDate(date){
      let res = date ? dayjs(date).format('YYYY-MM-DD HH:mm:ss') : ""
      return res
    },
    addUnit(val, unit){
      let res = ""
      if(val){
        res = val + unit
      }
      return res
    },
  },

  observers:{
    'm1': function (dataInfo){
      let reportInfo = {}
      // 充电度数
      reportInfo.degree = this.addUnit(parseFloat(dataInfo.degree).toFixed(2), 'kWh')
      // 充电时长
      reportInfo.duration = this.addUnit(dataInfo.duration, 'min')
      // 标称总能量
      reportInfo.ratedEnergy = this.addUnit(dataInfo.ratedEnergy, 'kWh')
      // 电池材料
      reportInfo.batterytype = dataInfo.batterytype
      // vin
      reportInfo.vin = dataInfo.vin
      // 充电场站
      reportInfo.chargingStation = dataInfo.chargingStation
      // 充电开始时间
      reportInfo.startTime = this.transDate(dataInfo.startTime)
      // 充电桩
      reportInfo.chargingPile = dataInfo.chargingPile
      // 充电结束时间
      reportInfo.endTime = this.transDate(dataInfo.endTime)
      // 开始SOC
      reportInfo.startSoc = this.addUnit(dataInfo.startSoc, '%')
      // 结束SOC
      reportInfo.endSoc = this.addUnit(dataInfo.endSoc, '%')

      // 评估结论
      reportInfo.evalConclusionRecords = dataInfo.evalConclusionRecords

      this.setData({
        reportInfo
      })
    }
  }


})
